import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

/**
 * 子弹类
 */
@Data
public class Shot implements Runnable {
    private int x;
    private int y;
    private int direct;
    private int speed = 1;
    private boolean isLive = true;

    public Shot(int x, int y, int direct) {
        this.x = x;
        this.y = y;
        this.direct = direct;
    }

    @Override
    public void run() {

        while (true) {
            try {
                Thread.sleep(50);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            switch (direct) {
                case 0:
                    // 上
                    y = y - speed;
                    break;
                case 1:
                    // 右
                    x = x + speed;
                    break;
                case 2:
                    // 下
                    y = y + speed;
                    break;
                case 3:
                    // 左
                    x = x - speed;
                    break;
            }
            if (x < 0 || x > 400 || y < 0 || y > 300) {
                this.isLive = false;
                break;

            }
        }
    }
}
